#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int n, k;
        cin >> n >> k;
        vector<int> arr(n + 1);
        for (int i = 1; i <= n; ++i)
            cin >> arr[i];

        if (n == 1) {
            cout << arr[1];
        }

        else
        {
            priority_queue<pair<int, int>> pq;
            for (int i = 2; i <= n; ++i)
                pq.push({ arr[i], i });

            long long t = arr[1];
            while (k-- && !pq.empty()) {
                pair<int, int> top = pq.top();
                int val = top.first;
                int idex = top.second;
                pq.pop();
                t += val;
            }

            vector<pair<int, int>> remain;
            while (!pq.empty()) {
                remain.push_back(pq.top());
                pq.pop();
            }

            sort(remain.begin(), remain.end(), [](const auto& a, const auto& b) {
                return a.second < b.second;
                });

            cout << t;
            for (const auto it : remain)
                cout << ' ' << it.first;
            cout << '\n';
        }
    }

    return 0;
}